﻿using System;
using System.Collections.Generic;
 
using System.Text;
using System.Runtime.InteropServices;


namespace HDF5
{
    using hid_t = System.Int32;
    using herr_t = System.Int32;
    using hsize_t = System.UInt64;
    using hssize_t = System.Int64;
    using hunsigned = System.UInt32;

    using hbool_t = System.UInt32;
    using htri_t = System.Int32;
    using ssize_t = System.Int64;

    using haddr_t = System.UInt64;

    using uint32_t = System.UInt32;
    using uint64_t = System.UInt64;

    using H5O_msg_crt_idx_t = System.UInt32;

    using size_t = System.UInt32;

    using off_t = System.Int32;

    using H5E_major_t = System.Int32;
    using H5E_minor_t = System.Int32;

    using time_t = System.Int64;
    using H5Z_filter_t = System.Int32;  


    public static class H5TB
    {
       
#region Creation
        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBmake_table( [In][MarshalAs(UnmanagedType.LPStr)] string table_title, hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string dset_name, 
            hsize_t nfields, [In]hsize_t nrecords, size_t type_size, 
            [In] string[] field_names, 
            [In] size_t[] field_offset, [In] hid_t[] field_types, 
            hsize_t chunk_size, 
            IntPtr fill_data, 
            int compress, 
            IntPtr data ) ;
#endregion Creation

#region Storage
        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBappend_records ( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string dset_name, 
            hsize_t nrecords, size_t type_size, [In] size_t[] field_offset, [In] size_t[] field_sizes, IntPtr data )  ;

        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBwrite_records ( hid_t loc_id, 
            [In][MarshalAs(UnmanagedType.LPStr)] string table_name, 
            hsize_t start, hsize_t nrecords, size_t type_size, 
            [In] size_t[] field_offset, [In] size_t[] field_sizes, IntPtr data) ;

        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBwrite_fields_name ( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string table_name, 
            [In][MarshalAs(UnmanagedType.LPStr)] string field_names, 
            hsize_t start, hsize_t nrecords, size_t type_size, [In] size_t[] field_offset, [In] size_t[] field_sizes, IntPtr data ) ;

        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBwrite_fields_index ( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string table_name, 
            int nfields, [In] int[] field_index, hsize_t start, hsize_t nrecords, size_t type_size, 
            [In] size_t[] field_offset, [In] size_t[] field_sizes, IntPtr data );
#endregion Storage

#region Modification
        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBdelete_record ( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string dset_name, 
            hsize_t start, hsize_t nrecords ) ;

        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBinsert_record (hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string dset_name, 
            hsize_t start, hsize_t nrecords, size_t type_size,  [In] size_t[] field_offset, [In] size_t[] field_sizes, IntPtr data  );

        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBadd_records_from ( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string dset_name1, 
            hsize_t start1, hsize_t nrecords, [In][MarshalAs(UnmanagedType.LPStr)] string dset_name2, hsize_t start2 ) ;

        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBcombine_tables ( hid_t loc_id1, [In][MarshalAs(UnmanagedType.LPStr)] string dset_name1, 
            hid_t loc_id2, [In][MarshalAs(UnmanagedType.LPStr)] string dset_name2, [In][MarshalAs(UnmanagedType.LPStr)] string dset_name3 ) ;

        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBinsert_field ( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string dset_name, 
            [In][MarshalAs(UnmanagedType.LPStr)] string field_name,  hid_t field_type, hsize_t position, 
            IntPtr fill_data, IntPtr data ) ;

        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBdelete_field ( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string dset_name, 
            [In][MarshalAs(UnmanagedType.LPStr)] string field_name );
#endregion Modification

#region Retrieval
        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBread_table( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string table_name, 
            size_t dst_size,  [In] size_t[] dst_offset, [In] size_t[] dst_sizes, IntPtr dst_buf ) ;

        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBread_records ( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string table_name, 
            hsize_t start, hsize_t nrecords, size_t type_size,  [In] size_t[] field_offset, [In] size_t[] dst_sizes,  IntPtr data ) ;

        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBread_fields_name ( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string table_name, 
            [In][MarshalAs(UnmanagedType.LPStr)] string field_names, 
            hsize_t start, hsize_t nrecords, size_t type_size,  
            [In] size_t[] field_offset, [In] size_t[] dst_sizes, IntPtr data) ;

        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBread_fields_index ( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string table_name, 
            int nfields, [In] int[] field_index, hsize_t start, hsize_t nrecords, size_t type_size,  
            [In] size_t[] field_offset, [In] size_t[] dst_sizes, IntPtr data) ;
#endregion Retrieval

#region Query
        [DllImport("hdf5_hldll.dll")]
        public static extern  herr_t H5TBget_table_info ( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string table_name, 
            out hsize_t nfields, out hsize_t nrecords );

        [DllImport("hdf5_hldll.dll")]
        public static extern herr_t H5TBget_field_info ( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string table_name, 
               [In,Out,MarshalAs(UnmanagedType.LPArray,ArraySubType=UnmanagedType.LPStr)]  string[] field_names,
          //  IntPtr[] ptr_field_names,
            [In,Out]size_t[] field_sizes, 
            [In,Out]size_t[] field_offsets, out size_t type_size  );
#endregion Query

   
    }
}
